<div id="app">
    <admin-page-header back>
        <bi-button type="primary" @click="edit">添加分组</bi-button>
     </admin-page-header>
    <div class="container">
        <div class="row">
            <div class="col-12">
                <bi-card title="分组列表">
                    <bi-table :data="list" :loading="loading" tree item-key="blockgroup_id"   min-height="300" :storagename="$user.getStorageName('web-blockgroup-list')" >
                        
                        <bi-table-column label="ID" name="blockgroup_id" width="100"></bi-table-column>
                        <bi-table-column label="分组名称" name="title" tree-fold ></bi-table-column>
                        <bi-table-column label="操作" width="150" v-slot="{row}">
                            <bi-button type="primary" @click="edit(row)"  >编辑</bi-button>
                            <bi-button type="warning" @click="handleDel(row)" >删除</bi-button>
                        </bi-table-column>
                    </bi-table>
                </bi-card>
            </div>
        </div>
    </div>
</div>

<script>
import groupEdit from 'block/group-edit-dialog.vue';

let app = admin.createApp({
    data(){
        return {
            list:[],
            loading:false
        }
    },
    methods:{
        edit(item){
            let title = item? '编辑分组':'添加分组';
        

            this.$dialog({
                title,
                type:'vue',
                content:admin.createApp(groupEdit,{item}),
                callback:(value)=>{
                    this.$user.delLocalStorage('web-block-group-input');
                    this.refresh();
                }
            })
        },
        handleDel(item){
            this.$confirm({text:'确定删除？',type:'warning'},()=>{
                this.$ajax({
                    url:this.$url({action:'GroupDel'}),
                    data:{
                        blockgroup_id:item.blockgroup_id
                    },
                    success:(res)=>{
                        this.refresh();
                        this.$user.delLocalStorage('web-block-group-input');
                        this.$toast({text:'删除成功',type:'success'});
                    }
                })
            })
        },
        refresh(){
            this.loading = true;
            this.$ajax({
                url:this.$url({action:'groupTree'}),
                success:(res)=>{
                    this.loading = false;
                    this.list = res.tree;
                }
            });
        }
    },
    mounted(){
        this.refresh();
    }
}).mount('#app');
</script>